package com.ruoyi.web.controller.manage;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.manage.domain.request.PasswordModificationRequest;
import com.ruoyi.manage.service.IAppPasswordModificationService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

/**
 * @Author: wwy
 * @Date: 2021/1/6 16:10
 */
@Api("移动端修改密码")
@RestController
@RequestMapping("/api")
public class AppPasswordModificationController {
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IAppPasswordModificationService appPasswordModificationService;
    /**
     * 忘记密码
     * @param passwordModificationRequest
     * @return
     */
    @PostMapping("/retrievePassword")
    public AjaxResult retrievePassword(@RequestBody PasswordModificationRequest passwordModificationRequest){
        return appPasswordModificationService.passwordModification(passwordModificationRequest);
    }

    /**
     * 修改密码
     * @param passwordModificationRequest
     * @return
     */
    @PostMapping("/resetPassword")
    public AjaxResult resetPassword(@RequestBody PasswordModificationRequest passwordModificationRequest, HttpServletRequest request){
        LoginUser loginUser = tokenService.getLoginUser(request);
        SysUser user = loginUser.getUser();
        //当前登录账号手机号，账号
        String phone = user.getUserName();
        passwordModificationRequest.setPhone(phone);
        return appPasswordModificationService.passwordModification(passwordModificationRequest);
    }
}
